#include "mainwindow.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<qobject.h>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    //ui
    ui->setupUi(this);
    this->setWindowTitle("精听英语");
    //进度条
    ui->progressBar->setRange(0,100);
    ui->progressBar->setValue(0);
    ui->progressBar->hide();
    //菜单
    this->getsrt.setText("安装语音转字幕软件");
    ui->menu_3->addAction(&(this->getsrt));
    //样式表
    this->setStyleSheet(QString::fromUtf8("#scrollArea_2{border:1px solid red}#MainWindow{border-image:url(:/new/prefix2/1.png)}"));//#MainWindow{border-image:url(:/new/prefix1/null-f443b1300b20f63.jpg)}//url(:/new/prefix2/C:/Users/清风 田茂福/Desktop/1.png)
    ui->menubar->setStyleSheet(QString::fromUtf8("border-image:url(:/new/prefix2/2.png)"));
    //yunxinshu
    this->yunxinshu=1;

    //网页
    this->wangzhan="https://fanyi.youdao.com/";
    this->showWangzhan();

    //数据库:
    QSqlDatabase mysql;
    if(QSqlDatabase::contains("qt_sql_default_connection"))
       mysql = QSqlDatabase::database("qt_sql_default_connection");
    else
      mysql = QSqlDatabase::addDatabase("QSQLITE");
    mysql.setDatabaseName("../myshujuku.db");
    //打开数据库
    if(mysql.open()==true)
    {
        QSqlQuery query;//不可以做成员,会报错
        //outfilename
        query.exec("select * from outfilename");
        if(query.first()==true)
        {
            this->outFilename=query.value(1).toString();
            qDebug()<<"outFilename="<<this->outFilename;
        }
        //
        query.exec("select * from appid ");
        if(query.first()==true)
        {
            this->trans_id=query.value("tofrom").toInt();qDebug()<<"mainwin_appid"<<trans_id;
        }
    mysql.close();
    }
    else
    {
        QMessageBox::warning(this,"未能打开数据库!",mysql.lastError().text());
        //结束程序:
    }



    //label
    ui->label_zhuangtaikuang->setText("请添加文件开始制作视频");
    //按钮状态
    ui->button_start->setEnabled(false);
    ui->Button_settitle->setEnabled(false);
    //菜单活动
    connect(ui->actionadd_txt_file,&QAction::triggered,this,&MainWindow::slotadd_txt_file);
    connect(ui->actionfont_and_back,&QAction::triggered,[=](){this->widget_font.show();});//背景
    connect(ui->actionset_outfile_pathname,&QAction::triggered,this,&MainWindow::slotsetoutfilename);
    connect(&this->getsrt,&QAction::triggered,this,&MainWindow::slot_getsrt);
    connect(ui->actionadd_files_in_batches,&QAction::triggered,[=](){wenjian.show();wenjian.updata();});
    connect(ui->action_setweb,&QAction::triggered,[=](){this->web.show();web.settext();});
    connect(ui->actionset_translation,&QAction::triggered,[=](){this->translation.show();translation.updata();});
    connect(ui->actionAdd_audio_to_the_video,&QAction::triggered,[=](){this->addyp_batches.show();});
    connect(ui->actionone_picture_video,&QAction::triggered,[=](){this->onepicture.show();onepicture.setoutfilename(this->outFilename);});
    connect(&onepicture,&one_picture_video::signal_create_over,[=](){ui->label_zhuangtaikuang->setText("已生成一张图片视频");});
    connect(ui->actionDeleting_subtitle_Files,&QAction::triggered,[=]()//删除字幕文件
    {
        QMessageBox mBox;
        mBox.setWindowTitle(("视频制作完成后是否删除字幕文件,和原视频?"));
                    mBox.setText((""));
                    mBox.setStandardButtons(QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::Cancel);
                    mBox.setButtonText(QMessageBox::StandardButton::Ok, ("删除"));
                    mBox.setButtonText(QMessageBox::StandardButton::Cancel, ("不删除"));
                    mBox.exec();
                    QMessageBox::StandardButton ret = mBox.standardButton(mBox.clickedButton());
                    switch (ret)
                    {
                    case QMessageBox::NoButton:
                        qDebug() << ("没有选择");
                        break;
                    case QMessageBox::Ok:
                        this->delete_str=true;
                        qDebug() << ("删除");
                        break;
                    case QMessageBox::Cancel:
                        this->delete_str=false;
                        qDebug() << ("不删除");
                        break;
                    default:
                        break;
                    }

    }

            );
    connect(ui->actionvideo_stitch,&QAction::triggered,[=](){video_stit.show();});
    connect(ui->actionSubtitle_display_style,&QAction::triggered,[=](){subtitle_style.show();});
    connect(&subtitle_style,&Subtitle_display_style::signal_ce_Subtitle_stop,this,&MainWindow::slot_Subtitle_style);

    //主窗口三个编辑区
    connect(ui->TextEdit_english,&QPlainTextEdit::textChanged,this,&MainWindow::slot_eng_filename);
    connect(ui->TextEdit_chinese,&QPlainTextEdit::textChanged,this,&MainWindow::slot_chi_filename);
    connect(ui->TextEdit_title,&QPlainTextEdit::textChanged,[=](){ui->Button_settitle->setEnabled(true);});

    //制作视频线程
    connect(&timer,&QTimer::timeout,[=](){this->slot_timesleep();});

    //next无效路径
    connect(this,&MainWindow::signal_nullpath,this,&MainWindow::slot_next);
    //任务列表
    connect(&this->wenjian,&wenjianshuju::signal_sddover,[=]()
    {
        if(tomp4isrun==false&&transisrun==false)
        {
            this->slot_next();
            return ;
        }
        else
        {
            ui->label_zhuangtaikuang->setText("线程正在运行,已经自动添加任务列表");
        }
    }
    );

    //网站
    connect(&this->web,&Setweb::signal_addover_web,this,&MainWindow::slot_setShowWeb);
    //翻译
    connect(&this->translation,&set_translation::signal_id,this,&MainWindow::slot_trans_id);
    connect(&this->timer_trans,&QTimer::timeout,this,&MainWindow::slot_sarttimer);//8秒后



    //添加音频
    connect(&this->yinping,&addyiping::signal_addyinping_over,this,&MainWindow::slot_addyinping_over);
    connect(&this->yinping,&addyiping::signal_outtext,[=](QString str){ui->axWidget->hide();ui->plainTextEdit->show();ui->plainTextEdit->appendPlainText(str);});

    //主窗口关闭
    connect(this,&MainWindow::destroyed,[=]()
    {


    });

}

MainWindow::~MainWindow()
{
    delete ui;
    this->wenjian.close();

}

void MainWindow::showWangzhan()
{
    qDebug()<<"void MainWindow::showWangzhan()";
    ui->plainTextEdit->hide();
    //
    this->ui->axWidget->setControl(QString::fromUtf8("{8856F961-340A-11D0-A96B-00C04FD705A2}"));//注册组件ID
    this->ui->axWidget->setProperty("DisplayAlerts",false);//不显示警告信息
    this->ui->axWidget->setProperty("DisplayScrollBars",true);//不显示滚动条
    QString webstr=QString("%1").arg(this->wangzhan);//设置要打开的网页
    this->ui->axWidget->dynamicCall("Navigate(const QString&)",webstr);//显示网页


    //webWidget->dynamicCall("Navigate(const QString&)", "file:///"+QCoreApplication::applicationDirPath()+"/drawChart/report.html");	//加载本地文件

}

void MainWindow::title_tmepname()
{
    QSqlDatabase mysql;
    if(QSqlDatabase::contains("qt_sql_default_connection"))
       mysql = QSqlDatabase::database("qt_sql_default_connection");
    else
      mysql = QSqlDatabase::addDatabase("QSQLITE");
    mysql.setDatabaseName("../myshujuku.db");

    int transid=ui->comboBox->currentIndex();

    if(ui->checkBox->isChecked())
        text_2=2;
    else
    {
        text_2=1;
    }
    //
    if(mysql.open()==true)
    {
        QSqlQuery query;
        query.exec("DROP TABLE title_filename");
        query.exec("create table title_filename( title varchar(200), filename varchar(200),outfilename varchar(300), trans_id int ,text_2 int,ce_stop bool  )");
        query.exec(QString("insert into title_filename(title,filename,outfilename,trans_id,text_2,ce_stop) values('%1','%2','%3',%4 ,%5,%6 )").arg(this->title).arg(this->path_txt_eglish).arg(this->tempfilename).arg(transid).arg(text_2).arg(ce_stop));
        //
        title.clear();
        mysql.close();
    }

    //进度条
    //数据库:
    QSqlDatabase mysqleng;
    if(QSqlDatabase::contains("qt_sql_default_connection"))
       mysqleng = QSqlDatabase::database("qt_sql_default_connection");
    else
      mysqleng = QSqlDatabase::addDatabase("QSQLITE");
    mysqleng.setDatabaseName("../myshujuku_engchi.db");

    //打开数据库
    if(mysqleng.open()==true)
    {
        QSqlQuery query;
        query.exec("select * from english");
        while (query.next())
        {
            this->time_length=query.value("time").toDouble();
        }

        mysqleng.close();
    }

}

void MainWindow::slotadd_txt_file()
{
    this->path_txt_eglish=QFileDialog::getOpenFileName(this,"选择英语字幕文件","","*.txt;*.srt;*.lrc");
    this->path_txt_chinese=QFileDialog::getOpenFileName(this,"选择中文字幕文件","","*.txt;*.srt;*.lrc");
    this->yinping_filename=QFileDialog::getOpenFileName(this,"音频文件","","*.mp3");

    QFileInfo info(outFilename);
    QString tempfile=info.absolutePath()+"/"+this->title+info.fileName();//保存文件名+title
    ui->label_zhuangtaikuang->setText(QString("英语字幕文件:%1;\n中文字幕文件:%2;\n保存路径:%3;\ntitle:%4;\n点击'开始制作'生成视频").arg(this->path_txt_eglish).arg(this->path_txt_chinese).arg(tempfile).arg(title));
    ui->button_start->setEnabled(true);
}

void MainWindow::slotsetoutfilename()
{
    //数据库:
    QSqlDatabase mysql;
    if(QSqlDatabase::contains("qt_sql_default_connection"))
       mysql = QSqlDatabase::database("qt_sql_default_connection");
    else
      mysql = QSqlDatabase::addDatabase("QSQLITE");
    mysql.setDatabaseName("../myshujuku.db");
    QString exectext;
    if(mysql.open()==true)
    {
    QString temp=QFileDialog::QFileDialog::getSaveFileName(this,tr("选择保存路径"),"/精听英语","*.mp4;; *.avi");
    //getExistingDirectory(this, "选择保存视频的目录", "./", QFileDialog::ShowDirsOnly);
    if(temp==nullptr)
    {
        return;
    }
    //开启事务
    QSqlDatabase::database().transaction();
    QSqlQuery query;
    //删除元数据
    exectext=QString("delete from outfilename where id =1");
    query.exec(exectext);
    //确定
    QSqlDatabase::database().commit();

    //更新
    this->outFilename=temp;
    //插入
    query.exec("create table outfilename(id int primary key, filename varchar(500))");
    exectext=QString("insert into outfilename(id,filename) values(1,'%1')").arg(this->outFilename);
    query.exec(exectext);
    //确定
    QSqlDatabase::database().commit();

    //qDebug()<<"exectext="<<exectext;
    qDebug()<<"outFilename2"<<this->outFilename;
    ui->label_zhuangtaikuang->setText(QString("outFilename=%1").arg(outFilename));
    }
    else{
        qDebug()<<"打开数据库失败main388";
    }
    mysql.close();
}


void MainWindow::on_button_start_clicked()
{
    qDebug()<<"void MainWindow::on_button_start_clicked()360";

    //是否已经存在任务了
    if(transisrun==true||tomp4isrun==true)
    {
        ui->label_zhuangtaikuang->setText("已存在任务");
        return;
    }


        QFile temp(this->path_txt_eglish);
    if(temp.open(QIODevice::ReadOnly)==false)
    {
        ui->label_zhuangtaikuang->setText(QString("打开英文字幕文件失败,请设置后重新点击''开始制作'';"));
        ui->button_start->setEnabled(false);
        return;
    }

    if(this->trans_id==0&&ui->checkBox->isChecked()==false&&ui->checkBox_ce_suanyu->isChecked()==false)//不用中文字幕
    {
        //中文
        QFile temp2(this->path_txt_chinese);
        if(temp2.open(QIODevice::ReadOnly)==false)
        {
            ui->label_zhuangtaikuang->setText(QString("打开中文字幕文件失败或未启用翻译,请设置后重新点击''开始制作'';"));
            ui->button_start->setEnabled(false);
            return;
        }

    }



    if(ui->comboBox->currentIndex()==0)
    {

        ui->label_zhuangtaikuang->setText("未设置源语言分行方法!!!");
        ui->button_start->setEnabled(false);
        return;
    }


     //ffmpeg不可含空格?
    if(tempfilename.contains(QRegExp(" "))==true)

    {
        ui->label_zhuangtaikuang->setText(QString("%1文件路径不能包含空格!!!").arg(tempfilename));
        ui->button_start->setEnabled(false);
        return;
    }

     if(this->yinping_filename.isEmpty()==false)
     {
         if(yinping_filename.contains(QRegExp(" "))==true)

         {
             ui->label_zhuangtaikuang->setText("音频文件路径不能包含空格!!!");
             ui->button_start->setEnabled(false);
             return;
         }
     }

     //输出文件名
     if(ui->checkBox_filenameistitle->isChecked())
     {
         QFileInfo info(path_txt_eglish);
         title=QString( info.fileName().left(info.fileName().length()-4));
     }
     if(ui->checkBox_yinpinnameistitle->isChecked())
     {
         QFileInfo info(yinping_filename);
         QString str=QString( info.fileName().left(info.fileName().length()-4));
         str=str.replace("mp3","");
         str=str.replace("MP3","");
         str=str.replace("_mp3","");
         str=str.replace("_MP3","");
         title=str;
     }
     if(this->title==nullptr)
     {
         QFileInfo info(path_txt_eglish);
         QFileInfo info2(outFilename);
         this->tempfilename=info2.absolutePath()+"/"+QString( info.fileName().left(info.fileName().length()-4)+info2.fileName().right(4) );

//         this->tempfilename=outFilename;
//         tempfilename=tempfilename.insert(tempfilename.length()-4,QString("%1").arg(yunxinshu));
         yunxinshu++;
     }
     else
     {
         QFileInfo info(outFilename);
         this->tempfilename=info.absolutePath()+"/"+this->title+info.fileName();//保存文件名+title
         ui->TextEdit_title->clear();
//         title.clear();存入数据库还需要,在
     }

     QString temp3(this->tempfilename);
     if(temp3==nullptr)
     {
         ui->label_zhuangtaikuang->setText(QString("未设置输出文件的路径,请设置后重新点击''开始制作''"));
         ui->button_start->setEnabled(false);
         return;
     }

     ui->label_zhuangtaikuang->setText(QString("英语字幕文件:%1;\n中文字幕文件:%2;\n保存路径:%3;\ntitle:%4;\n点击'开始制作'生成视频").arg(this->path_txt_eglish).arg(this->path_txt_chinese).arg(this->tempfilename).arg(this->title));
//制作视频
         if(ui->checkBox->isChecked())//关闭下半部分
         {
             //不翻译翻译
             mynot_translation nottrans;
             nottrans.sql_engchi(this->path_txt_eglish,this->path_txt_eglish);
             //制作视频
             //存入title tmepname //时间长度 最大运行数
             this->start_createmp4();

         }
         else
             if(ui->checkBox_ce_suanyu->isChecked())//双语字幕
             {
                 mynot_translation nottrans;
                 nottrans.chunru_shuanru(path_txt_eglish);

                 this->start_createmp4();
             }
         else
         if(this->trans_id==0)
         {
             //不翻译翻译
             mynot_translation nottrans;
             nottrans.sql_engchi(this->path_txt_eglish,this->path_txt_chinese);
             //制作视频
             //存入title tmepname //时间长度 最大运行数
             this->start_createmp4();
         }
         else
         {
             ui->label_newchi->setText("已启用翻译,请耐心等待");
             //开启翻译线程
             this->start_translation();
             //等待setother翻译完成
         }

    ui->button_start->setEnabled(false);
    return;

}


void MainWindow::on_Button_settitle_clicked()
{
     this->title=ui->TextEdit_title->toPlainText();
     ui->Button_settitle->setEnabled(false);
     qDebug()<<"title="<<title;
     ui->label_zhuangtaikuang->setText(QString("英语字幕文件:%1;\n中文字幕文件:%2;\ntitle:%3;\n点击'开始制作'生成视频").arg(this->path_txt_eglish).arg(this->path_txt_chinese).arg(this->title));
}

void MainWindow::slotnewchi(QString chi,double time)
{

    ui->label_newchi->setText(chi);
    //进度条
    ui->progressBar->show();

    ui->progressBar->setValue(time/(this->time_length)*100);

}


void MainWindow::slot_eng_filename()
{
    QString temp= ui->TextEdit_english->toPlainText();
    if(temp==nullptr)
    {
        return;
    }

    temp=temp.right(temp.length()-8);
    //qDebug()<<temp;
    this->path_txt_eglish=temp;
    ui->TextEdit_english->clear();
    ui->button_start->setEnabled(true);

    ui->label_zhuangtaikuang->setText(QString("英语字幕文件:%1;\n中文字幕文件:%2;\ntitle:%3;\n点击'开始制作'生成视频").arg(this->path_txt_eglish).arg(this->path_txt_chinese).arg(this->title));
    return;
}

void MainWindow::slot_chi_filename()
{

    QString temp=ui->TextEdit_chinese->toPlainText();
    if(temp==nullptr)
    {
        return;
    }

    //复制文本to txt
    if(temp.right(4)!=".txt"&&temp.right(4)!=".srt")
    {
        if(this->path_txt_eglish==nullptr)
        {
            ui->label_zhuangtaikuang->setText("请先添加英文文件路径!");
            //清除
            ui->TextEdit_chinese->clear();
            return;
        }
        QFile txt;
        QString path(this->path_txt_eglish);
        path=path.insert(path.length()-4,"复制");
        txt.setFileName(path);
        if(txt.open(QIODevice::ReadWrite)==true)
        {
            txt.write(ui->TextEdit_chinese->toPlainText().toUtf8().data());
        }
        else
        {
            qDebug()<<"mainwindos512打开复制文本txt失败";
        }
        txt.close();
        this->path_txt_chinese=path;
        ui->label_zhuangtaikuang->setText(this->path_txt_chinese);
        ui->label_zhuangtaikuang->setText(QString("英语字幕文件:%1;\n中文字幕文件:%2;\ntitle:%3;\n点击'开始制作'生成视频").arg(this->path_txt_eglish).arg(this->path_txt_chinese).arg(this->title));
        ui->button_start->setEnabled(true);
        //清除
        ui->TextEdit_chinese->clear();
        return;
    }
    //txt//srt
    temp=temp.right(temp.length()-8);
    //qDebug()<<temp;
    this->path_txt_chinese=temp;
    ui->label_zhuangtaikuang->setText(QString("英语字幕文件:%1;\n中文字幕文件:%2;\ntitle:%3;\n点击'开始制作'生成视频").arg(this->path_txt_eglish).arg(this->path_txt_chinese).arg(this->title));
    ui->TextEdit_chinese->clear();
    ui->button_start->setEnabled(true);
    return;
}

void MainWindow::slot_getsrt()
{
    //打开网址
    QDesktopServices::openUrl(QUrl(QLatin1String("https://github.com/wxbool/video-srt-windows")));

}
//下一次任务
void MainWindow::slot_next()
{
    //
    qDebug()<<"void MainWindow::slot_next()";
    static int next=0;
    if(next>4)
    {
        next=0;
    }
    qDebug()<<"next="<<next;

    QString eng[5];
    QString chi[5];
    QString tit[5];
    QString yinping[5];

    //数据库:
    QSqlDatabase mysql_next;
    if(QSqlDatabase::contains("qt_sql_default_connection"))
       mysql_next = QSqlDatabase::database("qt_sql_default_connection");
    else
      mysql_next = QSqlDatabase::addDatabase("QSQLITE");
    mysql_next.setDatabaseName("../myshujuku_filename.db");

    if( mysql_next.open()==true)
    {
        for(int i=0;i<5;i++)
        {
            QSqlQuery query(mysql_next);
            query.exec(QString("select * from filename where id = %1").arg(i));
            if(query.first()==true)
            {
                eng[i]=query.value("eng").toString();//qDebug()<< eng[i]<<580;
                chi[i]=query.value("chi").toString();//qDebug()<<chi[i]<<581;
                tit[i]=query.value("title").toString();//qDebug()<<tit[i]<<582;
                yinping[i]=query.value("yinping").toString();//qDebug()<<yinping[i]<<583;
            }
        }
       mysql_next.close();
    }
    else
    {
        QMessageBox::warning(this,"错误",mysql_next.lastError().text());
        return;
    }

    if(eng[0]==nullptr&&eng[1]==nullptr&&eng[2]==nullptr&&eng[3]==nullptr&&eng[4]==nullptr)
    {
        this->tomp4isrun=false;

        ui->label_zhuangtaikuang->setText("任务列表为空");
        if(mysql_next.open()==true)
        {
            QSqlQuery query;
            query.exec("DROP TABLE filename");
            qDebug()<<"删除fileanme595";
            mysql_next.close();
        }
        else
        {
            qDebug()<<"打开数据库失败";
        }
        return;
    }

    if(eng[next]==nullptr)
    {
        next++;
        //this->slot_next();
        emit signal_nullpath();
        return;
    }
    //
    this->path_txt_eglish=eng[next];qDebug()<<path_txt_eglish<<603;
    this->path_txt_chinese=chi[next];qDebug()<<path_txt_chinese<<604;
    this->title=tit[next];
    this->yinping_filename=yinping[next];qDebug()<<this->yinping_filename<<605;
    //
    QFile temp(this->path_txt_eglish);
    QFile temp2(this->path_txt_chinese);

//    if(this->trans_id==0)//不开启翻译
//    {
//        if(path_txt_chinese==nullptr)
//        {
//            ui->label_zhuangtaikuang->setText("未开启翻译且没有选择中文字幕文件...请重新设置");
//            return;
//        }
//        if(temp.open(QIODevice::ReadOnly)==false||temp2.open(QIODevice::ReadOnly)==false)
//        {
//            ui->label_zhuangtaikuang->setText(QString("多任务列表:打开字幕文件失败或未开启翻译,继续执行下一个任务"));
//            ui->button_start->setEnabled(false);
//            //非法路径,重新检索任务列表,next++;
//            //this->slot_next();//用信号好一点
//            next++;
//            emit signal_nullpath();
//            return;
//        }
//    }
//    else{
        if(temp.open(QIODevice::ReadOnly)==false)
        {
            ui->label_zhuangtaikuang->setText(QString("多任务列表:打开字幕文件失败,继续执行下一个任务"));
            ui->button_start->setEnabled(false);
            //非法路径,重新检索任务列表,next++;
            //this->slot_next();//用信号好一点
            next++;
            emit signal_nullpath();
            return;
        }
 //   }

    this->on_button_start_clicked();//start
    //删除
    //生成视频再删除void MainWindow::slot_helpnext()


    return;
}

void MainWindow::slot_timesleep()
{

    this->timer.stop();

    //
    tomp4isrun=false;

    if(this->yinping_filename.isEmpty()==false)
    {

        qDebug()<<"10秒后"
               <<"开始添加音频";
        //开始添加音频
        //ffmpeg不可含空格?veng=eng.replace(QRegExp("'"),QString("''"));         //Invalid argument,实际文件夹名字并未改变
//        QFile ypf(yinping_filename);
//        yinping_filename=yinping_filename.replace(QRegExp(" "),QString("_"));
//        ypf.setFileName(yinping_filename);

//        QFile spf(tempfilename);
//        tempfilename=tempfilename.replace(QRegExp(" "),QString("_"));
//        spf.setFileName(tempfilename);

        QString yinp_outfilename(tempfilename);
        yinp_outfilename=yinp_outfilename.insert(yinp_outfilename.length()-4,"精听");
        ui->label_newchi->setText("正在添加音频...");
        yinping.Addyinping(this->tempfilename,this->yinping_filename,yinp_outfilename);

        //等待添加完成
    }
    else
    {
        ui->label_newchi->setText("正在检查任务列表...");
        slot_next();
    }

    return;
}

void MainWindow::slot_helpnext()
{

    ui->label_newchi->setText("已生成视频,10秒后将自动添加音频");
    ui->progressBar->setValue(100);
    ui->progressBar->hide();

    //删除用过的数据filename
    QSqlDatabase mysql;
    if(QSqlDatabase::contains("qt_sql_default_connection"))
       mysql = QSqlDatabase::database("qt_sql_default_connection");
    else
      mysql = QSqlDatabase::addDatabase("QSQLITE");
    mysql.setDatabaseName("../myshujuku_filename.db");

    if( mysql.open()==true)
    {
        //("create table filename(id int primary key, eng varchar(500),chi varchar(500),title varchar(200))"
        QSqlQuery query(mysql);
        query.exec(QString("delete from filename where eng = '%1' ").arg(path_txt_eglish));//qDebug()<< QString("delete from filename where id = %1 ").arg(next);
        next++;
        mysql.close();
    }

    //删除用过的数据 字幕文件
//    if(this->delete_str==true)
//    {
//        DeleteFileOrFolder(this->path_txt_eglish);
//        if(this->path_txt_chinese.isEmpty()==false)
//        {
//            DeleteFileOrFolder(this->path_txt_chinese);
//        }
//    }

    this->wenjian.updata();
    qDebug()<<"已关闭线程tomp4";
    this->timer.start(10000);//必须休眠10秒,bug来源;

    return;
}

void MainWindow::slot_setShowWeb(int num)
{
    qDebug()<<"void MainWindow::slot_setShowWeb(int num)";
    //数据库:
    QSqlDatabase mysql;
    if(QSqlDatabase::contains("qt_sql_default_connection"))
       mysql = QSqlDatabase::database("qt_sql_default_connection");
    else
      mysql = QSqlDatabase::addDatabase("QSQLITE");
    mysql.setDatabaseName("../myshujuku.db");
    if(mysql.open()==true)
    {
        QSqlQuery query(mysql);
        query.exec(QString("select * from web where id = %1 ").arg(num));
        if(query.first()==true)
        {
            this->wangzhan=query.value("webname").toString();
            qDebug()<<"wangzhan="<<this->wangzhan;
        }

        mysql.close();
    }

    this->showWangzhan();

    return;
}

void MainWindow::slot_trans_id(int id)
{
    this->trans_id=id;
    qDebug()<<"trans_id="<<trans_id;
    if(id!=0)
    {
        ui->label_newchi->setText("已开启自动翻译...");

    }
    else{
        ui->label_newchi->setText("已关闭翻译...");
    }
}

void MainWindow::slot_helptrans()
{

    transisrun=false;
    ui->progressBar->hide();
    ui->label_newchi->setText("已翻译成功,等待制作视频...");


    start_createmp4();

}

void MainWindow::slot_sarttimer()
{

    this->timer_trans.stop();
    qDebug()<<"二次翻译 2秒后";
    slot_trans_startnext();
    return;
}


void MainWindow::slot_showproject(QString str,double line)
{
    ui->label_newchi->setText(str);
    ui->progressBar->show();
    ui->progressBar->setValue(line*100);//qDebug()<<line;
}

void MainWindow::slot_Subtitle_style()
{
    ce_stop=true;
}

void MainWindow::slot_addyinping_over()
{

   ui->label_newchi->setText("添加音频成功,正在检查任务列表");
   ui->plainTextEdit->hide();
   ui->axWidget->show();

   if(this->delete_str==true)
   DeleteFileOrFolder(this->tempfilename);//删除原视频

    //检查任务列表
    this->slot_next();
}

bool MainWindow::DeleteFileOrFolder(const QString &strPath)
{
    if (strPath.isEmpty() || !QDir().exists(strPath))//是否传入了空的路径||路径是否存在
        return false;

    QFileInfo FileInfo(strPath);

    if (FileInfo.isFile())//如果是文件
        QFile::remove(strPath);
    else if (FileInfo.isDir())//如果是文件夹
    {
        QDir qDir(strPath);
        qDir.removeRecursively();
    }
    return true;
}

void MainWindow::start_translation()
{
     transisrun=true;
     mythr_translation *translation_text=new mythr_translation(NULL);
     connect(translation_text,&mythr_translation::signal_fanyiover,this,&MainWindow::slot_helptrans);
     connect(translation_text,&mythr_translation::signal_fanyiover,translation_text,&QObject::deleteLater);
     connect(translation_text,&mythr_translation::signal_showproject,this,&MainWindow::slot_showproject);
     //next
     connect(translation_text,&mythr_translation::signal_trans_next,[=](QString **temp,int biaoshi,int maxline){this->eng=temp ;this->maxline=maxline ;this->biaoshi=biaoshi ;timer_trans.start(2000);});
     connect(translation_text,&mythr_translation::signal_trans_next,translation_text,&QObject::deleteLater);
     translation_text->sql_trans(this->trans_id,path_txt_eglish);

    return;
}

void MainWindow::start_createmp4()
{
    this->tomp4isrun=true;

    mythr_createmp4 *TOmp4=new mythr_createmp4(NULL);
    connect(TOmp4,&mythr_createmp4::singal_newchi,this,&MainWindow::slotnewchi);
    connect(TOmp4,&QThread::finished,this,&MainWindow::slot_helpnext);
    connect(TOmp4,&QThread::finished,TOmp4,&QObject::deleteLater);

    this->title_tmepname();
    TOmp4->start();

    return;

}

void MainWindow::slot_trans_startnext()
{

    translation_next *translation=new translation_next(NULL);

    connect(translation,&translation_next::signal_showproject,[=](QString str,double line){slot_showproject(str,line);});
    connect(translation,&translation_next::signal_nexttrans_over,this,&MainWindow::slot_helptrans);
    connect(translation,&translation_next::signal_nexttrans_over,translation,&QObject::deleteLater);

    translation->trans_next(eng,biaoshi,maxline);

    return;


}

